package mk.company.fin.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
//import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import mk.company.fin.FinConstants;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Index;

@Entity
@Table(name = FinConstants.Tables.KONTO_CLASS)
public class KontoClass extends Model {

	private static final long serialVersionUID = -2911881094017253393L;

	private Long id;
	private String value;
	private String description;
	private List<KontoGroup> kontoGroups;
	
	
	@Id
	@Column(name = "id_konto_class")
	@GeneratedValue//(strategy = GenerationType.SEQUENCE)
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}

	@Column(unique = true, nullable = false, length = 1)
	@Index(name = FinConstants.Tables.KONTO_CLASS + "_search")
	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		if (StringUtils.isNotEmpty(value) && value.length() == 1) {
			this.value = value;
		}
	}

	@Column
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@OneToMany(mappedBy = "kontoClass", orphanRemoval = true, fetch = FetchType.LAZY)
	public List<KontoGroup> getKontoGroups() {
		return kontoGroups;
	}

	public void setKontoGroups(List<KontoGroup> kontoGroups) {
		this.kontoGroups = kontoGroups;
	}
	
	@Override
	public String toString() {
		return getValue();
	}
	
}
